var table;
$(function() {
	table = dataTable.init('table', {
		url : webPath + '/admin/rsRoles/query',
		toolbar : '#toolbar',
		cols : [ [ {
			checkbox : true,
			fixed : true
		}, {
			field : 'roleId',
			title : '角色id',
			fixed : 'left'
		}, {
			field : 'roleName',
			title : '角色名',
			fixed : 'left',
		}, {
			field : 'description',
			title : '说明',
			fixed : 'left',
		} ] ],
		searchData : {
			roleName : $('#roleName').val()
		}
	});

});
function query() {
	table.search({
		roleName : $('#roleName').val()
	});
}
function save() {
	var selections = table.getAllSelected();
	var id = '';
	for (var i = 0; i < selections.length; i++) {
		id = id + selections[i].roleId + ",";
	}
	$
			.ajax({
				url : webPath + '/admin/user/editUserRole?uid=' + uid
						+ "&roleId=" + id,
				type : 'post',
				success : function(ret) {
					if (ret > 0) {
						parent.layer.alert('提交成功', function(index) {
							parent.layer.close(index);
							window.location.href = RS.webPath
									+ "/admin/user?organId=" + organId;
						});
					} else {
						parent('提交失败');
					}
				},
				error : function() {
					parent('提交失败');
				}

			});
}

function stateFormatter(value, row, index) {
	var roleId = row.roleId;
	for (var i = 0; i < roleIds.length; i++) {
		if (roleId == roleIds[i]) {
			return true;
		}
	}
	return false;

}